// Achievement by G3X / GeXeH - Enjoy
// Version 1.0

// Achievement: Kill 100 Headcrab NPCs.

local killed = achievements.GetValue( "Head Humper", "total", 0 )

local headcrab = { "npc_headcrab", "npc_headcrab_fast", "npc_headcrab_black" }
local function PlayerKilledNPC( msg )
	local victim, inflictor, attacker = msg:ReadString(), msg:ReadString(), msg:ReadEntity()
	
	if ( killed != 100 && attacker == LocalPlayer() ) then
		if ( table.HasValue( headcrab, victim ) ) then
			killed = math.Clamp( killed + 1, 0, 100 )
			achievements.SetValue( "Head Humper", "total", killed )
			achievements.Update( "Head Humper", killed / 100, killed .. "/100" )
		end
	end		
	
	return victim, inflictor, attacker
end
usermessage.AddHook( "PlayerKilledNPC", "Achievements.HeadHumper", PlayerKilledNPC )

achievements.Register( "Head Humper", "Kill 100 Headcrab NPCs.", "achievements/headhumper", killed / 100, killed .. "/100" )